import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * This class is the mainframe of the application.
 * 
 * @author Paul Poston, Matt Minch, SHEM ZAKEM, Kyle Phillips
 *         
 */

public class ProjectMainFrame
{
	private int inset = 120;
	private PageRetriever pr;
	private final JFrame mainFrame = new JFrame("Project 1");
	private final JPanel mainPanel;
	private final JButton submit = new JButton("Submit");
	private final JCheckBox bool = new JCheckBox("Multithread?");
	private final JTextField url = new JTextField(
			"http://css.insttech.washington.edu/~mealden/");
	private final JTextField keywords = new JTextField("keywords.txt");

	/**
	 * Constructor that makes the frame and sets its default properties.
	 */
	public ProjectMainFrame()
	{
		mainFrame.setBounds(inset, inset, 300, 500);
		mainPanel = new JPanel();
		mainPanel.setLayout(new GridLayout(0, 1));
		buildContent();
		mainPanel.add(url);
		mainPanel.add(keywords);
		mainPanel.add(bool);
		mainPanel.add(submit);
		mainFrame.setVisible(true);
		mainFrame.add(mainPanel);
		mainPanel.repaint();
		mainPanel.revalidate();
		mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}

	/**
	 * Adds the action listener which builds the PageRetriever object to get info.
	 */
	private void buildContent()
	{
		submit.addActionListener(new ActionListener()
		{

			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				if (url.getText() != "" && keywords.getText() != "")
				{
					pr = new PageRetriever(url.getText(), new File(keywords.getText()),
							mainPanel, bool.isSelected());

				}
			}

		});

	}

	/**
	 * Main Method.
	 * 
	 * @param args
	 */
	public static void main(String[] args)
	{
		new ProjectMainFrame();

	}
}
